clear;
close all;
clc;
rad=0.2;
thre = 0.3;
% freqs= 25:25:5000; %just a random frequency
freqs = 50:50:3000;
fs = 44100;
left_sound1=[];
right_sound1=[];
for version = 1:5
    version
    [YY fs2]=audioread(['C:\Users\gaiy\OneDrive - Saint Louis University\speech_experiments\Analyze_localization_result\3Dio_all\Protocol_31\Protocol_31_deg30_' num2str(version) '.mp3']);
    recorded_sound=resample(YY,441,320);
    left_sound1=[left_sound1; recorded_sound(:,1)];
    right_sound1=[right_sound1; recorded_sound(:,2)];
end
% left_sound2=[];
% right_sound2=[];
% for version = 1:10
%     version
%     [YY fs2]=audioread(['C:\Users\gaiy\OneDrive - Saint Louis University\speech_experiments\Analyze_localization_result\3Dio_all\Protocol_41\Protocol_41_deg30_' num2str(version) '.mp3']);
%     recorded_sound=resample(YY,441,320);
%     left_sound2=[left_sound2; recorded_sound(:,1)];
%     right_sound2=[right_sound2; recorded_sound(:,2)];
% end
f1=figure;
% f2=figure;
for ifreql = 1:length(freqs)
    freq = freqs(ifreql)
    tdur = 40/freq;
    [SL,SR,freq_pos,flag]=mySTFT(left_sound1,right_sound1,fs,thre,tdur);
    % normalization:
%     [SL1,SR1]=Normalize(SL,SR);
L_or_R = 1;
    SR1=Normalize_Both(SL,SR,L_or_R);
    [Y Ind] = min(abs(freq_pos - freq));
    X_P1 = [real(SR1(Ind,flag>0))' imag(SR1(Ind,flag>0))'];

    figure(f1)
    subplot(4,6,ifreql)
    plot(X_P1(:,1),X_P1(:,2),'b.');hold on;
    %     C = sen_centers(ifreql,:);
    %     plot(C(1,1),C(1,2),'bo','Markersize',20,'LineWidth',2);hold on;
    axis([-1 1 -1 1])
    hold on;
    axis square

%     [SL,SR,freq_pos,flag]=mySTFT(left_sound2,right_sound2,fs,thre,tdur);
%     % normalization:
%     [SL2,SR2]=Normalize(SL,SR);
%     [Y Ind] = min(abs(freq_pos - freq));
%     X_P2 = [real(SR2(Ind,flag>0))' imag(SR2(Ind,flag>0))'];
% 
%     figure(f2)
%     subplot(3,5,ifreql)
%     plot(X_P2(:,1),X_P2(:,2),'r.');hold on;
    title(num2str(freq))
%     axis([-1 1 -1 1])
%     hold on;
%     axis square
    pause(0.2)
end
